<?php
$type='module_product';
if(!empty($_POST['submit'])&&$_POST["submit"]==lang_show('submit'))
{
	unset($_POST['submit']);
	foreach($_POST as $pname=>$pvalue)
	{
		$sql="select * from ".CONFIG." where `index`='$pname' and type='$type'";
		$db->query($sql);
		if($db->num_rows())
		   $sql1=" update ".CONFIG." SET value='$pvalue',type='$type' where `index`='$pname'";
		else
		   $sql1="insert into ".CONFIG." (`index`,value,type) values ('$pname','$pvalue','$type')";
		$db->query($sql1);
	}
	/****更新缓存文件*********/
	$write_config_con_array=read_config($type);//从库里取出数据生成数组
	$write_config_con_str=serialize($write_config_con_array);//将数组序列化后生成字符串
	$write_config_con_str=str_replace("'","\'",$write_config_con_str);
	$write_config_con_str='<?php $'.$type.'_config = unserialize(\''.$write_config_con_str.'\');?>';//生成要写的内容
	$fp=fopen('../config/'.$type.'_config.php','w');
	fwrite($fp,$write_config_con_str,strlen($write_config_con_str));//将内容写入文件．
	fclose($fp);
	/*********************/
	admin_msg("module.php?m=product&s=module_config.php","设置成功");
	exit;
}
//===读库函数，生成config形式的数组====
function read_config($type)
{
	global $db;
	$sql="select * from ".CONFIG." where type='$type'";
	$db->query($sql);
	$re=$db->getRows();
	foreach($re as $v)
	{
		$index=$v['index'];
		$value=$v['value'];
		$configs[$index]=$value;
	}
	return $configs;
}
$reg_config=read_config($type);
if(!$reg_config)
{
	@include('config/'.$type.'_config.php');
	$con=$type.'_config';
	$reg_config=$$con;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><?php echo lang_show('admin_system');?></title>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
<link href="main.css" rel="stylesheet" type="text/css" />
<script src="../script/prototype.js" type=text/javascript></script>
</head>
<body>
<div class="bigbox">
	<div class="bigboxhead">模块配置</div>
	<div class="bigboxbody">
	<form name="sysconfig" action="" method="post">
	<table width="100%" cellspacing="0">
	   <tr class="theader"><td colspan="2">SEO</td></tr>
		   <tr>
			  <td width="17%"  align="left" >Title</td>
			  <td align="left" >
			  <input class="text" name="title" type="text" id="title" value="<?php echo $reg_config['title'];?>" >			  </td>
			</tr>
                <tr>
                  <td height="40" align="left">Keyword</td>
                  <td align="left" ><input class="text" name="keyword" type="text" id="keyword" value="<?php echo $reg_config['keyword'];?>"></td>
                </tr>
                <tr>
                  <td height="40" align="left"><pre id="line1">Description</pre></td>
                  <td align="left" ><textarea name="description" cols="10" rows="3" class="text" id="description"><?php echo $reg_config['description'];?></textarea></td>
                </tr>
                <tr class="theader">
                  <td height="23" colspan="2" >信息发布</td>
                </tr>
                <tr>
                  <td height="32" align="left">产品打开方式</td>
                  <td align="left" ><input class="text" name="opentype" type="text" id="opentype" value="<?php echo $reg_config['opentype'];?>" />
                    <br />
                    <span class="bz"> 0为前台打开，1为在用户商铺中打开 </span></td>
                </tr>
                <tr>
                  <td height="40" align="left">信誉状态</td>
                  <td align="left" ><input class="text" name="credit" type="text" id="credit" value="<?php echo $reg_config['credit'];?>" />
                    <br />
                    <span class="bz"> 7天包换|正品保证|如实描述</span></td>
                </tr>
                <tr>
                  <td height="40" align="left">产品单位</td>
                  <td align="left" ><input class="text" name="unit" type="text" id="unit" value="<?php echo $reg_config['unit'];?>">
                    <br />
                    <span class="bz">
                    件|只|条|个|箱|kg|吨|克<br />
                  Piece|Box|Kg</span></td>
                </tr>
                <tr>
                  <td height="40" align="left">有效期</td>
                  <td align="left" ><input class="text" name="validTime" type="text" id="validTime" value="<?php echo $reg_config['validTime'];?>" />
                    <br />
                    <span class="bz"> 7天|15天|1个月|3个月|6个月|1年|永久 <br />
7 days|15 days|1 month|3 months|6 months|1 year|permanent</span></td>
                </tr>
                <tr>
                  <td height="40" align="left">产品类型</td>
                  <td align="left" ><input class="text" name="ptype" type="text" id="ptype" value="<?php echo $reg_config['ptype'];?>" />
                    <br />
                    <span class="bz">全新|二手|闲置|其它<br />
New|Old|unused|Other</span></td>
                </tr>
                <tr>
                  <td height="40" align="left">交易类别</td>
                  <td align="left" ><input class="text" name="trade_type" type="text" id="trade_type" value="<?php echo $reg_config['trade_type'];?>" />
                    <br />
                    <span class="bz">零售|小额批发|大量批发<br />
					Retail|Small Wholesale|Large Wholesale</span></td>
                </tr>
        <tr>
          <td width="17%" height="40" align="right">&nbsp;</td>
          <td align="left" ><input  class="btn" type="submit" name="submit" value="<?php echo lang_show('submit');?>"></td>
        </tr>
      </table>
	</form>
	</div>
</div>
</body>
</html>